package fun.wlfj.servlet;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fun.wlfj.vo.VoteTask;

/**
 * Servlet implementation class manageservlet
 */
@WebServlet("/manageservlet")
public class manageservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public manageservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		// 这里什么都不做 直接将请求转发
		@SuppressWarnings("unchecked")
		LinkedList<VoteTask> taskList = (LinkedList<VoteTask>)this.getServletContext().getAttribute("TaskList");
		if(taskList == null){
			taskList = new LinkedList<VoteTask>();
			this.getServletContext().setAttribute("TaskList", taskList);
		}
		
		request.setAttribute("CurrentVoteInstance", taskList.isEmpty() ? null : taskList.getLast());
		request.getRequestDispatcher("manager.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
